<template>
  <div>
    <c-title class="circle_title" :hide="false" :text="'我的区域代理'"></c-title>
    <main>
      <div v-for="(item, index) in list" :key="index" class="item">
        <div class="left">
          <img
            :src="item.avatar_image"
          />
          <div class="info">
            <div class="info-title">{{ item.nickname }}</div>
            <div class="info-id">id:{{ item.id }}</div>
          </div>
        </div>
        <div class="right">
          <div class="agency_level">{{ item.level_name }}</div>
          <div class="area">{{ item.area }}</div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { scrollMixin } from "../../../utils/mixin"; //引入加载更多
import {Toast} from "vant";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      list: [],
      current_page: 1,
      last_page: 1,
      isLoadMore: true
    };
  },
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      $http
        .post("plugin.area-merchant.frontend.modules.agent.controllers.records.index")
        .then(res => {
          if (res.result == 1) {
            this.list = res.data.page_list.data;
            this.last_page = res.data.page_list.last_page;
          }else{
            Toast(res.msg)
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getMoreData() {
      this.isLoadMore = false;
      if (this.current_page >= this.last_page) {
        return;
      } else {
        this.current_page = this.current_page + 1;
        $http
          .post("plugin.area-merchant.frontend.modules.agent.controllers.records.index", { page :this.current_page})
          .then(res => {
            this.isLoadMore = true;
            if (res.result == 1) {
              this.list = this.list.concat(res.data.page_list.data);
              this.last_page = res.data.page_list.last_page;
            }else{
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
img {
  margin-left: 0;
  margin-right: 0;
}

div.item {
  margin: 1rem 1rem 0;
  display: flex;
  justify-content: space-between;
  border-radius: 0.3rem;
  background: #fff;
  padding: 0.5rem;

  .left {
    display: flex;
    align-items: center;
  }

  img {
    width: 3rem;
    height: 3rem;
    border-radius: 100px;
  }

  .right {
    display: flex;
    flex-direction: column;
    text-align: right;
    justify-content: space-between;
  }

  .info {
    margin-left: 0.5rem;
    height: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: baseline;
  }

  .area {
    color: #666;
  }
}
</style>
